package com.zmj.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zmj.entity.UserInfo;
import com.zmj.service.IUserInfoService;
import com.zmj.service.impl.UserInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getInfo")
public class GetInfoServlet extends HttpServlet {
    IUserInfoService userInfoService=new UserInfoServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String num=req.getParameter("pageNum");
        if (num==null){
            num="1";
        }
        int pageNum=Integer.parseInt(num);
        PageHelper.startPage(pageNum,2);
        String search=req.getParameter("search");
        List<UserInfo> infolist=userInfoService.selALLInfo(search,"desc");
        PageInfo pageInfo=new PageInfo(infolist);

        long total=pageInfo.getTotal();
        List<UserInfo> list =pageInfo.getList();
        req.setAttribute("infolist",list);
        req.setAttribute("pageInfo",pageInfo);
        req.getRequestDispatcher("main.jsp").forward(req,resp);
    }
}
